#include "game_byte.h"
#include <stdlib.h>
#include <stdio.h>

CGameByteStack::CGameByteStack(size_t size,size_t num){
  _size = size;
  _num = num;
  _capacity = size * num;
  _ptr = (BYTE*)malloc(_capacity);

  for(size_t i = 0;i < num;i++){
    CGameByteStack_t *ctx = new CGameByteStack_t();
    ctx->_ptr = _ptr + i * size;
    ctx->_size = size;

    _vec.push_back(ctx);
    _stack.push_back(ctx);

    // printf("_ptr[%d]: %p\n",i,ctx->_ptr);
  }
}

CGameByteStack_t* CGameByteStack::alloc(){
  if(0 >= _stack.size())
    return NULL;

  std::vector<CGameByteStack_t*>::iterator itr = _stack.begin();
  CGameByteStack_t* ret = (*itr);
  _stack.erase(itr);
  
  return ret;
}
void CGameByteStack::dealloc(CGameByteStack_t* ctx){
  _stack.push_back(ctx);
}
